package cn.stylefeng.guns.sys.modular.system.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.modular.system.entity.BtyMdFuzhumxz;
import cn.stylefeng.guns.sys.modular.system.model.params.BtyMdFuzhumxzParam;
import cn.stylefeng.guns.sys.modular.system.service.BtyMdFuzhumxzService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;


/**
 * 网上建店信息gcg_wsjd控制器
 *
 * @author jiangge
 * @Date 2021-09-08 10:50:59
 */
@Controller
@RequestMapping("/btyMdFuzhumxz")
public class BtyMdFuzhumxzController extends BaseController {

    private String PREFIX = "/modular/system/btyMdFuzhumxz";

    @Autowired
    private BtyMdFuzhumxzService btyMdFuzhumxzService;

    /**
     * 跳转到主页面
     *
     * @author jiangge
     * @Date 2021-09-08
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/btyMdFuzhumxz.html";
    }

    /**
     * 新增页面
     *
     * @author jiangge
     * @Date 2021-09-08
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/btyMdFuzhumxz_add.html";
    }

    /**
     * 编辑页面
     *
     * @author jiangge
     * @Date 2021-09-08
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/btyMdFuzhumxz_edit.html";
    }

    /**
     * 新增接口
     *
     * @author jiangge
     * @Date 2021-09-08
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(BtyMdFuzhumxzParam btyMdFuzhumxzParam) {
        this.btyMdFuzhumxzService.add(btyMdFuzhumxzParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author jiangge
     * @Date 2021-09-08
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(BtyMdFuzhumxzParam btyMdFuzhumxzParam) {
        this.btyMdFuzhumxzService.update(btyMdFuzhumxzParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author jiangge
     * @Date 2021-09-08
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(BtyMdFuzhumxzParam btyMdFuzhumxzParam) {
        this.btyMdFuzhumxzService.delete(btyMdFuzhumxzParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author jiangge
     * @Date 2021-09-08
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(BtyMdFuzhumxzParam btyMdFuzhumxzParam) {
        BtyMdFuzhumxz detail = this.btyMdFuzhumxzService.getById(btyMdFuzhumxzParam.getBtyMdFuzhumxzId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author jiangge
     * @Date 2021-09-08
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(BtyMdFuzhumxzParam btyMdFuzhumxzParam) {
        if(StringUtils.isNotBlank(btyMdFuzhumxzParam.getDate())){
            String date = btyMdFuzhumxzParam.getDate().replaceAll("-", "").replaceAll(" ", "");
            btyMdFuzhumxzParam.setKjYear(Integer.valueOf(date.substring(0,4)));
            btyMdFuzhumxzParam.setKjMonth(Integer.valueOf(date.substring(4,6)));
        }

        return this.btyMdFuzhumxzService.findPageBySpec(btyMdFuzhumxzParam);
    }

    /**
     * 导入辅助明细账-用友费用明细
     */
    @RequestMapping("/importFzmxz")
    @ResponseBody
    public ResponseData importFzmxz(@RequestParam("file") MultipartFile file) {
        ResponseData data = new ResponseData();
        try {
            data = this.btyMdFuzhumxzService.importFzmxz(file);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseData.success();
    }

}


